<?php

class Length {
  var $id;
  var $length;
  var $timeScale;
  var $readable;
  
  function __construct() {
  }
  
	function Reason() {
	}
	
	function init() {
    $this->id = -1;
    $this->reason = "Breaking Server Rules";
  }
  
  function getId() {
    return $this->id;
  }
  
  function getLength() {
    return $this->length;
  }
  
  function setId($id) {
    $this->id = $id;
  }
  
  function setLength($length) {
    $this->length = $length;
  }
  
  function getTimeScale() {
    return $this->timeScale;
  }
  
  function setTimeScale($timeScale) {
    $this->timeScale = $timeScale;
  }
  
  function getReadable() {
    $this->readable = $this->length . " " . $this->timeScale;
    if($this->length == 1) {
      if($this->timeScale == "minutes")
        $this->readable = $this->length . " minute";
      if($this->timeScale == "hours")
        $this->readable = $this->length . " hour";
      if($this->timeScale == "days")
        $this->readable = $this->length . " day";
      if($this->timeScale == "weeks")
        $this->readable = $this->length . " week";
      if($this->timeScale == "months")
        $this->readable = $this->length . " month";
    }
    
    if($this->length == 0) {
      $this->readable = "Forever";
    }
    
    return $this->readable;
  }
  
  function getLengthInSeconds() {
    $lengthInSec = 0;
    // Convert the length to seconds
    if($this->timeScale == "minutes") {
      $lengthInSec = $this->length*60;
    } else if($this->timeScale == "hours") {
      $lengthInSec = $this->length*3600;
    } else if($this->timeScale == "days") {
      $lengthInSec = $this->length*3600*24;
    } else if($this->timeScale == "weeks") {
      $lengthInSec = $this->length*3600*24*7;
    } else if($this->timeScale == "months") {
      $lengthInSec = $this->length*3600*24*7*4; // 4 weeks a month
    }
    return $lengthInSec;
  }
}
?>
